<?php
require_once('lib/model.php');
require_once('lib/diy.php');
$smarty = new Smarty_Diycity();

if (isset($_POST['email'])) {
  $local_alert = new DiyModel("local_email_alerts");
  $address_slice = explode('/', $_POST['address']);
  $size = sizeof($address_slice);
  switch ($size) {
  case 1:
    $input = array('email' => $_POST['email'],
		   'address1' => $address_slice[0]);
    break;
  case 2:
    $input = array('email' => $_POST['email'],
		   'address1' => $address_slice[0],
		   'address2' => $address_slice[1]);
    break;
  case 3:
    $input = array('email' => $_POST['email'],
		   'address1' => $address_slice[0],
		   'address2' => $address_slice[1],
		   'address3' => $address_slice[2]);
    break;
  }
  if ($local_alert->save($input) != false) {
    $smarty->display('local_alert_thanks.tpl');    
  } else {
    echo $local_alert->getError();
  }
 } else {
  if (!isset($_POST['address'])) {
    exit;
  }
  $smarty->assign('address', $_POST['address']);
  $smarty->display('local_alert_subscribe.tpl');
 }
?>
